package net;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Client {
	
	private Logger logger = Logger.getLogger(Client.class.getName());

	private String host;
	private int port;
	
	private Socket socket; 
	
	private OutputStream outputStream;
	private InputStream inputStream;
	
	private BufferedWriter writer;
	private BufferedReader reader;
	
	public Client(String host, int port) throws UnknownHostException, IOException {
		
		this.host = host;
		this.port = port;
		
		Socket socket = new Socket(host, port);
		
		outputStream = socket.getOutputStream();
		inputStream = socket.getInputStream();
		
		writer = new BufferedWriter(new OutputStreamWriter(outputStream));
		reader = new BufferedReader(new InputStreamReader(inputStream));
		
		logger.log(Level.INFO, "Client Initialized");
	}

	public void close() throws IOException{
		writer.close();
		reader.close();
		outputStream.close();
		inputStream.close();
	}
	
	public OutputStream getOutputStream() {
		return outputStream;
	}

	public InputStream getInputStream() {
		return inputStream;
	}

	public BufferedWriter getWriter() {
		return writer;
	}

	public BufferedReader getReader() {
		return reader;
	}
}
